package com.niit.tsr.repository;

import com.niit.tsr.bean.BorrowRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface BorrowRepository extends JpaRepository<BorrowRecord,Integer> {

    @Query("from BorrowRecord  b where b.user_id = :user_id")
    List<BorrowRecord> findUserId(@Param("user_id") Integer user_id);
    @Modifying
    @Transactional
    @Query("delete from BorrowRecord b where b.borrow_id = :borrow_id")
    void deleteBorrowRecord(Integer borrow_id);

    @Modifying
    @Transactional
    @Query("update BorrowRecord b set b.return_date= current_timestamp where b.borrow_id = :borrow_id")
    void updateBorrowDateByBookId(@Param("borrow_id") Integer borrow_id);


}
